<?php
/* ----------------------------------------------------------
--               JacoCMS by Jaco Ruit                      --
-------------------------------------------------------------
--     JacoCMS is Open Source and is lincenced under       --
--             GNU General Public Licence v3               --
--          http://www.gnu.org/copyleft/gpl.html           --
-------------------------------------------------------------
--       Please don't remove any text from the footers.    --
-------------------------------------------------------------
-- Credits:   * Jaco Ruit          ~     Scripts,MySQL     --     
-----------------------------------------------------------*/

#Installation Script JacoCMS


if((!isset($_POST['mysqlhost'])) && (!isset($_POST['mysqluser'])) && (!isset($_POST['mysqlpw'])) && (!isset($_POST['mysqldbname'])))
{
	echo "<p>Error, no mysqlcreds found.</p>";
}
else
{
	$mysqlhost = $_POST['mysqlhost'];
	$mysqluser = $_POST['mysqluser'];
	$mysqlpw = $_POST['mysqlpw'];
	$mysqldbname = $_POST['mysqldbname'];
	$error = null;
	$error2 = null;
	$conn = mysql_connect($mysqlhost, $mysqluser, $mysqlpw) or $error = mysql_error();
	mysql_select_db($mysqldbname) or $error2 = mysql_error();
	if(($error == null) &&($error2 == null) )
	{
	
	$conffile=
	"<?php
	/* ----------------------------------------------------------
	--               JacoCMS by Jaco Ruit                      --
	-------------------------------------------------------------
	--     JacoCMS is Open Source and is lincenced under       --
	--             GNU General Public Licence v3               --
	--          http://www.gnu.org/copyleft/gpl.html           --
	-------------------------------------------------------------
	--       Please don't remove any text from the footers.    --
	-------------------------------------------------------------
	-- Credits:   * Jaco Ruit          ~     Scripts,MySQL     --     
	-----------------------------------------------------------*/

	// Configuration file of JacoCMS
	// Enter your details here!


	#MySQL Database Host 
	\$databasehost = '" . $mysqlhost . "';

	#MySQL Database Username
	\$databaseuser = '" . $mysqluser . "';

	#MySQL Database Password
	\$databasepassword = '" . $mysqlpw . "';

	#MySQL Database Name
	\$databasename = '" .$mysqldbname ."';

	?>";
	
	$writer = fopen('config.php', 'w');
	fwrite($writer, $conffile);
	fclose($writer);
	
?>
<html>
	<head>
		<title>JacoCMS - DB Connection Test</title>
		<link href="style.css" rel="stylesheet" type="text/css" /> 
	</head>
	<body>
	<div id="panel">
		<center><img src="../style/default/logo.png" /></center>
		<h3>JacoCMS Installer ~ Database Connection Tester</h3><br />
		<p>Connection succesful!</p><br />
		<p>Please go to the <a href="install.php?step=3">next</a> step</p>
	</div>
	</body>
</html>

<?php
	}
	else
	{
?>
<html>
	<head>
		<title>JacoCMS - DB Connection Test</title>
		<link href="style.css" rel="stylesheet" type="text/css" /> 
	</head>
	<body>
	<div id="panel">
		<center><img src="../style/default/logo.png" /></center>
		<h3>JacoCMS Installer ~ Database Connection Tester</h3><br />
		<p>Connection error!</p><br />
		<p><?php echo $error ?></p><br />
		<p><?php echo $error2 ?></p><br />
		<p>Please go <a href="install.php?step=2">back</a></p>
	</div>
	</body>
</html>
<?php
	}
}
?>
